/*
 *  Copyright 2010 Mahbub Mozadded Sowrov.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package com.sowrov.afrigis.tools.timesheet;

/**
 * Write about the class here
 *
 * @author Mahbub Mozadded (Sowrov)
 * @date Apr 13, 2010
 */
public class PostData {

    private int projectIndex;

    private int activityIndex;
    
    private String projectId;

    private String projectRate;

    private String activityId;

    private boolean billable;

    private String description;

    private String decimalTime;

    private String strDate;

    private String serverId = ""; //get the post id from the server

    private int localId = -1; //

    private int status = 0;

    public PostData() {
        this.projectId = "";
        this.projectRate = "";
        this.activityId = "";
        this.description = "";
        this.strDate = "";
        this.decimalTime = "";
        this.billable = false;
        this.activityIndex = -2;
        this.projectIndex = -2;
        this.status = 0;
    }

    public PostData(int localId, String projectId, String projectRate, String activityId,
                    String date, String description, String strHour, boolean billable) {
        this.localId = localId;
        this.projectId = projectId;
        this.projectRate = projectRate;
        this.activityId = activityId;
        this.billable = billable;
        this.description = description;
        this.decimalTime = strHour;
        this.strDate = date;
        this.activityIndex = -2;
        this.projectIndex = -2;
        this.status = 0;
    }

    public String getActivityId() {
        return activityId;
    }

    public void setActivityId(String activityId) {
        this.activityId = activityId;
    }

    /**
     * get activity index for the drop down combo-box, it search in user project list and activity list
     * if the value was not already set.
     * 
     * @return zero base integer index of the activity
     */
    public int getActivityIndex() {
        if (activityIndex==-2) {
            User user = User.getInstance();
            this.activityIndex = user.getProjectById(this.projectId).getActivityIndexById(this.activityId);
        }
        return activityIndex;
    }

    public void setActivityIndex(int activityIndex) {
        this.activityIndex = activityIndex;
    }

    /**
     * get project index for the drop down combo-box, is search in user project list if the index value was not
     * already set.
     * 
     * @return zero base integer index
     */
    public int getProjectIndex() {
        if (this.projectIndex == -2) {
            this.projectIndex = User.getInstance().getProjectIndexById(this.projectId);
        }
        return projectIndex;
    }

    public void setProjectIndex(int projectIndex) {
        this.projectIndex = projectIndex;
    }

    public boolean isBillable() {
        return billable;
    }

    public String getBillable() {
        return billable?"True":"False";
    }

    public void setBillable(boolean billable) {
        this.billable = billable;
    }

    public boolean isSubmitted() {
        return this.getStatus()==2;
    }

    public void setServerId(String postId) {
        this.serverId = postId;
    }

    public String getServerId() {
        return serverId;
    }

    public int getLocalId() {
        return localId;
    }

    public void setLocalId(int localId) {
        this.localId = localId;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getProjectId() {
        return projectId;
    }

    public void setProjectId(String projectId) {
        this.projectId = projectId;
    }

    public String getStrDate() {
        return strDate;
    }

    public void setStrDate(String strDate) {
        this.strDate = strDate;
    }

    public String getDecimalTime() {
        return decimalTime;
    }

    public void setDecimalTime(String decimalTime) {
        this.decimalTime = decimalTime;
    }

    public int getStatus() {
        return status;
    }

    /**
     * submitted = 2, modified = 1, new = 0
     * 
     * @param status
     */
    public void setStatus(int status) {
        this.status = status;
    }

    public String getProjectRate() {
        return projectRate;
    }

    public void setProjectRate(String projectRate) {
        this.projectRate = projectRate;
    }

    @Override
    public String toString(){
        return "ServerId: "+this.serverId+" Porjectid: "+this.projectId+" ActivityId: "+this.activityId+
                "ProjectRate: "+this.projectRate+" Date: "+this.strDate+" Status: "+this.status+
                " Time: "+this.decimalTime+"\nDescription: "+this.description;
    }
}
